import os
from PIL import Image, ImageDraw, ImageFont
from gtts import gTTS

# 配置参数
ASSETS_DIR = "assets/letters"
SOUNDS_DIR = "sounds/letters"
FONT_PATH = "/app/assets/fonts/BalooBhai2-Regular.ttf"
COLORS = [(255,87,34), (33,150,243), (76,175,80), (255,193,7), (156,39,176)]

# 生成字母图标（200x200 PNG）
def generate_icons():
    os.makedirs(ASSETS_DIR, exist_ok=True)
    font = ImageFont.truetype(FONT_PATH, 120)
    
    for char_code in range(65, 91):
        letter = chr(char_code)
        img = Image.new('RGBA', (200, 200), (0,0,0,0))
        draw = ImageDraw.Draw(img)
        
        # 绘制背景形状
        draw.rounded_rectangle([10,10,190,190], radius=30, fill=COLORS[char_code%5])
        
        # 绘制字母
        w, h = draw.textbbox((0, 0), letter, font=font)[2:4]
        draw.text(((200-w)/2, (200-h)/2-10), letter, font=font, fill=(255,255,255))
        
        img.save(f"{ASSETS_DIR}/{letter.lower()}_icon.png")

# 生成字母发音（使用Google TTS）
def generate_audio():
    os.makedirs(SOUNDS_DIR, exist_ok=True)
    
    for char_code in range(65, 91):
        letter = chr(char_code)
        tts = gTTS(text=letter, lang='en', slow=True)
        tts.save(f"{SOUNDS_DIR}/{letter.lower()}.mp3")

if __name__ == "__main__":
    generate_icons()
    generate_audio()